package br.uff.busuffweb.model;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author jthiago
 */
@NamedQueries({
    @NamedQuery(name = "Onibus.getTodos",
    query = "select o from Onibus o order by o.id"),
    
    @NamedQuery(name = "Onibus.getPorPlaca",
    query = "select o from Onibus o " +
            " where o.placa = ?")
})
@Entity
@SequenceGenerator(sequenceName = "seq_onibus", name = "Sequencia")
@Table(name = "onibus")
@XmlRootElement
public class Onibus implements Serializable {
    
    @Id
    @GeneratedValue(generator = "Sequencia", strategy = GenerationType.AUTO)
    private Long id;
    
    @Column(nullable = false, unique = true)
    private String placa;
    
    private String descricao;
    
    @ManyToOne
    private Circuito circuitoAtual;
    
    @OneToMany(fetch = FetchType.LAZY, mappedBy="onibus")
    private List<LogLocalizacao> logLocalizacoes;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getPlaca() {
        return placa;
    }

    public void setPlaca(String placa) {
        this.placa = placa;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 79 * hash + Objects.hashCode(this.id);
        hash = 79 * hash + Objects.hashCode(this.placa);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Onibus other = (Onibus) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        if (!Objects.equals(this.placa, other.placa)) {
            return false;
        }
        return true;
    }

    public Circuito getCircuitoAtual() {
        return circuitoAtual;
    }

    public void setCircuitoAtual(Circuito circuitoAtual) {
        this.circuitoAtual = circuitoAtual;
    }

    @XmlTransient
    public List<LogLocalizacao> getLogLocalizacoes() {
        return logLocalizacoes;
    }

    public void setLogLocalizacoes(List<LogLocalizacao> logLocalizacoes) {
        this.logLocalizacoes = logLocalizacoes;
    }
}
